const path = require('path')

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    // entry: {
    //     index:'./src/index.js',
    //     another:'./src/another-module.js'
    // },
    // entry: {
    //     index: {
    //         import: './src/index.js',
    //         dependOn: 'shared'
    //     },
    //     another: {
    //         import: './src/another-module.js',
    //         dependOn: 'shared'
    //     },
    //     shared: 'lodash'
    // },
    entry: {
        index: './src/index.js',
        another: './src/another-module.js'
    },
    output: {
        // 为不同的入口配置出口
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist'),
        clean: true,
    },
    mode: 'development',
    plugins: [
        new HtmlWebpackPlugin({
            template: "./public/index.html",
            filename: "test.html",
            inject: true
        })
    ],
    module: {
        rules: [
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            }, {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env'],
                        plugins: [
                            [
                                '@babel/plugin-transform-runtime'
                            ]
                        ]
                    }
                }
            }
        ]
    },
    devServer: {
        static: "./dist",
        open: true,
        host: 'local-ip',
        onListening(s) {
            let { address: ads, port } = s.server.address()
            console.log('http:' + ads + ':' + port);
        }
    },
    devtool: 'inline-source-map',
    optimization: {
        splitChunks: {
            chunks: 'all'
        }
    }
}
